var StockUpperLimitBoard = function () {
  var template = /* html */ `
    <div class="stock-upper-limit-board" v-loading.fullscreen.lock="loading">
      <div class="upper-limit-title">
        <span>超出库存上限物料</span>
        <div v-if="stockList!==null" class="upper-limit-stat">
          物料总数:{{stockList.length}}
        </div>
      </div>
      <div class="upper-limit-content" v-if="isShow">
        <template v-if="stockList!==null">
          <stock-table :stocks="stockList" type="max"></stock-table>
        </template>

        <div v-else class="no-data">
          暂无超出库存上限的物料
        </div>
      </div>
    </div>
  `;

  return {
    mixins: [boardRunningMixin],

    data: function () {
      return {
        loading: false,
        isShow: false,
        stockList: null
      };
    },

    created: function () {
      this.loading = true;
      var self = this;
      this.setStockList(true).then(function () {
        self.loading = false;
        self.isShow = true;
        self.boardRunning();
      }).catch(function () {
        self.loading = false;
        self.isShow = true;
      });
    },

    methods: {
      setStockList: function (hasAlert) {
        if (hasAlert === undefined) {
          hasAlert = false;
        }

        var self = this;
        return ajaxRequest('displayView/warehouseBeyondMax', {}, true, hasAlert).then(function (stockList) {
          stockList = _.map(stockList, function (stock) {
            stock = new StockInfo(stock, 'max');
            return stock;
          });
          stockList = _.orderBy(stockList, ['limitCount'], ['desc']);
          for (var i = 0; i < stockList.length; i++) {
            var stock = stockList[i];
            stock.rowIndex = i;
          }
          self.stockList = stockList;
          return stockList;
        });
      },

      boardRunning: function () {
        this.clearTimeoutList();

        this.resetStockList();
      },

      resetStockList: function () {
        var self = this;
        var timeout = setTimeout(function () {
          self.setStockList().then(function () {
            self.resetStockList();
          }).catch(() => {});
          self.timeoutList[0] = null;
        }, 30 * 60 * 1000);
        this.timeoutList[0] = timeout;
      }
    },

    components: {
      StockTable: StockTable
    },

    template: template
  };
}();
